package com.jcj.house;

import com.jcj.framework.Game;
import com.jcj.framework.Input.TouchEvent;
import com.jcj.framework.gl.Camera2D;
import com.jcj.framework.gl.SpriteBatcher;
import com.jcj.framework.impl.GLScreen;
import com.jcj.framework.math.OverlapTester;
import com.jcj.framework.math.Rectangle;
import com.jcj.framework.math.Vector2;
import java.util.List;
import javax.microedition.khronos.opengles.GL10;

public class InfoScreen extends GLScreen {
    Camera2D guiCam;
    SpriteBatcher batcher;
    Rectangle returnBounds;
    Rectangle mainBounds;
    Vector2 touchPoint;

    public InfoScreen(Game game) {
        super(game);
        guiCam = new Camera2D(glGraphics, 320, 480);
        batcher = new SpriteBatcher(glGraphics, 100);
        returnBounds = new Rectangle(277, 480-30-78, 53, 78);
        touchPoint = new Vector2();
    }
    
    @Override
    public void update(float deltaTime) {
        List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
        game.getInput().getKeyEvents();
        int len = touchEvents.size();
        for (int i = 0; i < len; i ++) {
            TouchEvent event = touchEvents.get(i);
            if (event.type == TouchEvent.TOUCH_UP) {
                touchPoint.set(event.x, event.y);
                guiCam.touchToWorld(touchPoint);

                if (OverlapTester.pointInRectangle(returnBounds, touchPoint)) {
                    game.setScreen(new MainMenuScreen(game));
                    return;
                }
                
            }
        }
    }

    @Override
    public void present(float deltaTime) {
        GL10 gl = glGraphics.getGL();
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        guiCam.setViewportAndMatrices();

        gl.glEnable(GL10.GL_TEXTURE_2D);
        
        batcher.beginBatch(Assets.info);
        batcher.drawSprite(160, 240, 320, 480, Assets.infoRegion);
        batcher.endBatch();

        gl.glDisable(GL10.GL_BLEND);
    }

    @Override
    public void pause() {
    	Settings.save(game.getFileIO());   
    }

    @Override
    public void resume() {

    }

    @Override
    public void dispose() {
        
    }
}
